package router

import (
	"ci-control-backend/common/httpx"
	"ci-control-backend/controller"
	"ci-control-backend/middleware"
	"github.com/gin-gonic/gin"
)

var hostController *controller.HostController

func init() {
	hostController = new(controller.HostController)
}

func SetupHostRoutes(r *gin.Engine) {
	// 以下API无需验证
	noAuth := r.Group("/host")
	noAuth.Use()
	{
		noAuth.GET("/channel/:key", httpx.Controller(hostController.Channel))
		noAuth.PUT("/channel/:key", httpx.Controller(hostController.ReportStatus))
	}

	// 以下API需要用户权限
	userAuth := r.Group("/host")
	userAuth.Use(httpx.Middleware(middleware.UserAuth))
	{
		userAuth.POST("/new", httpx.Controller(hostController.NewHost))
		userAuth.DELETE("/:id", httpx.Controller(hostController.DelHost))
		userAuth.PUT("/:id", httpx.Controller(hostController.UpdateHost))
		userAuth.GET("/list", httpx.Controller(hostController.GetHostList))
		userAuth.GET("/hookKey", httpx.Controller(hostController.GetHookKey))
	}
}
